<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<%@ page import="java.util.*" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.activiti.engine.ProcessEngine" %>
<%@ page import="org.activiti.engine.RepositoryService" %>
<%@ page import="org.activiti.engine.RuntimeService" %>
<%@ page import="org.activiti.engine.HistoryService" %>
<%@ page import="org.activiti.engine.runtime.ProcessInstance" %> 
<%@ page import="org.activiti.engine.history.HistoricProcessInstance" %>
<%@ page import="org.activiti.engine.history.HistoricTaskInstance" %>
<%@ page import="org.activiti.engine.identity.User" %>
<%@ page import="com.DateUtil" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link type="text/css" rel="stylesheet" charset="utf-8" href="<%=request.getContextPath() %>/css/base.css"/>
<title>history</title>
</head>
<%
User user = (User)session.getAttribute("user");

WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
//ProcessEngine engine = (ProcessEngine)context.getBean("processEngine");
RepositoryService repository = (RepositoryService)context.getBean("repositoryService");
RuntimeService runtime = (RuntimeService)context.getBean("runtimeService");
HistoryService historyService = (HistoryService)context.getBean("historyService");

List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().startedBy(user.getId()).list();

int i = 0;
%>
<body>
<table align="center" width="100%">
	<caption>history</caption> 
	<tr>
		<th align="center" scope="col"></th>
		<th align="center" scope="col">Id</th>
		<th align="center" scope="col">StartTime</th>
		<th align="center" scope="col">EndTime</th>
		<th align="center" scope="col"></th>
	</tr>
	<%for(HistoricProcessInstance d : list){%>
	<tr>
		<td class="row"><%=++i %></td>
		<td class="row">
			<%=d.getId() %>
		</td>
		<td class="row"><%=DateUtil.format(d.getStartTime(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"><%=DateUtil.format(d.getEndTime(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"></td>
	</tr>
	<tr>
		<td class="row" colspan="5">
		<%
		List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(d.getId()).list();
		for(HistoricTaskInstance h : taskList){
			out.write(h.getName()+"</br>");
		} 
		%>
		</td>
	<tr>
	<%} %>
</table>
</body>
</html>